﻿<?php //header("Content-Type: text/html; charset=UTF-8");
function b() {print '<br/>';}
//$q=utf8_decode(utf8_encode($_GET["q"]));
$q=$_GET["q"];
/*print $q;
print utf8_decode("Ã¤");
*/
/*print urldecode('%C3%A4');b();

print utf8_decode($q); b();
print urldecode($q); b();
print utf8_encode($q); b();
print utf8_encode(urldecode($q)); b();
print urldecode(utf8_encode($q)); b();*/

//$q=strtolower($_GET["q"]);
//$q = strtolower(utf8_decode($_GET["q"]));
//print $q;
$table=strtolower($_REQUEST["table"]);
//if (!$q) return;
require_once("konfiguration.html");
if (strlen($q)<=2)$search=$q.'%';
else $search='%'.$q.'%';
$result=mysql_query("SELECT distinct canword FROM $table WHERE canword like '$search' ORDER BY canword LIMIT 5 ");

//print  "SELECT distinct canword FROM $table WHERE canword like '$search' ORDER BY canword LIMIT 8";
if ( ! $result ) { die('Error query: ' . mysql_error()); }

for($count = 1; $count <= 5; $count++) 
{
    $row=mysql_fetch_array($result);
    //print_r($row);
    //print $row[0]."|".$row[1]."\n";  //Wenn ein 2.Wort mitgesendet werden soll. 
	if (strtolower($row[0])==$q)$result_array[0]=$row[0];
	else $result_array[$count]=$row[0];
	
}

//if (in_array($q,$result_array2)) {print $q."\n";$result_array = array_diff($result_array, array($q));}
for($count = 0; $count <= 5; $count++)if ($result_array[$count])print $result_array[$count]."\n"; 

?>
